<?php
require_once 'abstractModel.php';

class NoticeModel extends AbstractModel{
	//NOTICE TABLE NAME
	const TABLE_NAME_NOTICE = 'tNotice';
	
	//NOTICE COLUMN NAMES
	const NOTICE_INDEX = "NIndex";
	const NOTICE_CREATE_DATE = 'NCreatedDate';
	const NOTICE_CONTENT = 'NContent';
	const NOTICE_START_DATE = 'NStartDate';
	const NOTICE_END_DATE = 'NEndDate';
	
	public function __construct(){
		parent::__construct();
		$this->targetTable=self::TABLE_NAME_NOTICE;
	}
	
	/**
	 *
	 * @todo 空のメッソド継承したが、使う必要なし
	 */
	
	public function setTargetTable($targetTable){}
	
	/**
	 *
	 * @see AbstractModel::insert()
	 * @todo  お知らせをDB,TABLE(tNotice)にinsertするメッソド
	 * @param 下の３つのparameterが必要
	 * @param 1.(String)noticeContent - お知らせの内容
	 * @param 2.(Date)noticeStartDate - お知らせが始まる日時, data("Y-m-d")
	 * @param 3.(Date)noticeEndDate   - お知らせが終わる日時, data("Y-m-d")
	 * @return boolean
	 */
	
	public function insert(){
		$_nTitle=func_get_arg(0);
		$_nContent=func_get_arg(1);
		$_nStartDate=func_get_arg(2);
		$_nEndDate=func_get_arg(3);
		$sth = $this->db->prepare("Insert into tNotice(NTitle,NContent,NStartDate,NEndDate) values(?, ?, ?, ?)");
		$sth->bindParam(1, $_nTitle);
		$sth->bindParam(2, $_nContent);
		$sth->bindParam(3, $_nStartDate);
		$sth->bindParam(4, $_nEndDate);
		return $sth->execute();
	}
	
	/**
	 * 
	 * @see AbstractModel::select($sth)
	 * @todo  お知らせをDB,TABLE(tNotice)にselectするメッソド
	 * @param parameterにstatement
	 * @return array
	 */
	// not completed
	public function select($sth){
		return parent::select($sth);
		/*
		if (func_num_args()==1){
			$sth = $this->db->prepare("Select * from tNotice where NIndex = :id");
			$sth->bindValue(":id", func_get_arg(0));
			print func_get_arg(0);
			print_r($sth);
		} else if(func_num_args()==0) {
			$sth = $this->db->prepare("Select * from tNotice");
		} else {
			return;
		}
		
		//$sth = $this->db->prepare("Select * from tNotice");
		$sth->execute();
		$sth->setFetchMode(PDO::FETCH_ASSOC);
		$arr = array();
		while($row=$sth->fetch()){
			$arr[]=$row;
		}
		return $arr;
		*/
	}
	
	/**
	 * (non-PHPdoc)
	 * @see AbstractModel::update()
	 * @todo  お知らせをDB,TABLE(tNotice)にupdateするメッソド
	 * @param 下の4つのparameterが必要
	 * @param 1.(String)noticeContent - お知らせの内容
	 * @param 2.(Date)noticeStartDate - お知らせが始まる日時, data("Y-m-d")
	 * @param 3.(Date)noticeEndDate   - お知らせが終わる日時, data("Y-m-d")
	 * @param 4.(String)NIndex        - お知らせのIndex
	 * @return boolean
	 */
	
	public function update(){
		$sth = $this->db->prepare("Update tNotice SET NContent=?, NStartDate=?, NEndDate=? WHERE NIndex=?");
		$sth->bindParam(1, func_get_arg(0));
		$sth->bindParam(2, func_get_arg(1));
		$sth->bindParam(3, func_get_arg(2));
		$sth->bindParam(4, func_get_arg(3));
		return $sth->execute();
	}
	
	/**
	 * (non-PHPdoc)
	 * @see AbstractModel::delete($where)
	 * @todo  お知らせをDB,TABLE(tNotice)にupdateするメッソド
	 * @param 下の1つのparameterが必要
	 * @param 1.(String)NIndex        - お知らせのIndex
	 * @return boolean
	 */
	
	public function delete($where){
		$sth = $this->db->prepare("Delete from tNotice where NIndex=?");
		$sth->bindParam(1, $where);
		return $sth->execute();
	}
}
